/**
 * Created by Administrator on 14-12-1.
 */
define(function(require, exports){
	var $        = require("jquery");
	var pubjs    = require('pubjs');
	var view     = require('@base/view');
	var util     = require('util');
	var drop     = require('@base/common/drop');
	var grid     = require('@base/grid');
	var labels   = require('modules/labels').labels;
	var labelsAll   = require('modules/labels');
	//-----------------------------下面是新侧栏sidebar

	// 侧栏搜索形式基类
	var SideBarSearch = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarSearch',
				'parentClass': '', // 父样式
				'searchTip': ''
			});

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			var searchCfg = {
				'width': 160,
				'target': el
			}
			if(c.searchTip){
				searchCfg.searchTip = c.searchTip;
			}
			if(c.parentClass){
				el.parent().addClass(c.parentClass);
			}

			self.createAsync(c.name|| 'search', '@base/common/base.search', searchCfg);
		},
		getValue: function(){
			var c = this.getConfig();
			if(this.$[c.name || 'search']){
				return this.$[c.name || 'search'].getValue();
			}
		},
		reset: function(){
			var c = this.getConfig();
			if(this.$[c.name || 'search']){
				this.$[c.name || 'search'].reset();
			}
		}
	});
	exports.search = SideBarSearch;

	// 侧栏单选形式基类
	var SideBarRadio = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio',
				'title': '',
				'data': null, // 选中的选项
				'key': 'id', // 选项记录关键字字段名
				'name': 'name', // 选项记录显示字段名
				'value': '', // 默认值
				'compareValue': false, // 使用比较默认值，作为是否返回结果渲染描述
				'url': '', //
				'all': false,
				'all_item': {
					id: 0,
					name: LANG('全部')
				},
				'defaultLimit': 8, // 默认要显示的个数
				'view_model': {
					'data': [],
					'value': '',
					'defaultLimit': 8, // 默认要显示的个数
					'moreLimit': 8, // 显示更多的个数
					'moreText': LANG('更多...'),
					'moreTextUp': LANG('收起↑'),
					'moreClick': this.eventMoreClick
				}
			});

			this.$sysParam = null;

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			if(c.data && c.data.length) {
				self.setKey(c.data);

				if(c.all){
					c.data.unshift(c.all_item);
				}
			}
			c.data = self.langName(c.data);
			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;
			self.vm.$.defaultLimit = +c.defaultLimit;
			self.vm.$.moreLimit = +c.defaultLimit;


			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div ms-each-item="data" class="content">',
							'<label class="" ms-class="act:value==item.id" ms-if="item" ms-visible="$index<moreLimit">',
								'<input ms-value="item.id" type="radio" ms-duplex-text="value" ms-visible="false">',
								'<i class="icon-circle-double icon-circle-thin mr5" ms-visible="true" ms-class="icon-circle-thin:value!=item.id"/>',
								'{{item.name}}',
							'</label>',
						'</div>',
						'<div class="more" ms-click="moreClick()" ms-visible="defaultLimit<data.length" ms-text="moreLimit==data.length?moreTextUp:moreText"></div>',
					'</div>',
				'</div>'
			].join('')));

			self.vm.watch('value', self.eventRadioChange);

			if(c.url){
				self.load();
			}
		},
		langName: function (data) {
			for(var i =0,j = data.length; i<j;i++){
				data[i].name = LANG(data[i].name);
			}
			return data;
		},
		eventRadioChange: function(value) {
			var self = this;
			// var c = self.getConfig();
			var data = util.clone(self.vm.getItem('data'));
			value = util.find(data, value, 'id');
			if(value) {
				this.fire('sidebarFilterGroup', {
					type: this._.name,	//子模块名
					data: [value],	//值集合
					value: value,	//值对象
					id: value.id || '',	//id
					desc: self.renderResultDesc(value)
				});
			}
		},
		eventMoreClick: function(){
			var vm = this.vm.$;
			if(vm.moreLimit > vm.defaultLimit){
				vm.moreLimit = vm.defaultLimit;
			}else{
				vm.moreLimit = vm.data.length;
			}
			return false;
		},
		setValue: function(value){
			this.vm.$.value = String(value);
			return this;
		},
		setKey: function(data){
			var c = this.getConfig();
			if(data){
				util.each(data, function(item){
					if(item){
						item.id = item[c.key];
						item.name = item[c.name];
					}
				});
			}
			return data || {};
		},
		setParam: function(param){
			var c = this.getConfig;
			this.$sysParam = util.extend({}, c.param, param);
			return this;
		},
		load: function(){
			var c = this.getConfig();
			var param = util.extend({}, c.param, this.$sysParam);
			pubjs.mc.send(c.url, param, this.onData.bind(this));
		},
		onData: function(err, data){
			var self = this;
			var c = self.getConfig();

			if (err){
				pubjs.error(err.message);
				return false;
			}
			if(data && data.items){
				self.vm.$.data = self.langName(self.setKey(data.items));
			}else if(Array.isArray(data)){
				self.vm.$.data = self.langName(self.setKey(data));
			}

			if(c.all){
				self.vm.$.data.unshift(self.langName(c.all_item));
			}
		},
		reload: function(){
			if(this.getConfig('url')) {
				this.load();
			}

			return this;
		},
		reset: function(){
			// this.vm.reset();
			// this.reload();
			var self = this;
			var c = self.getConfig();
			self.vm.$.value = c.value;
			return self;
		},
		show: function(){
			this.Super('show', arguments);
			this.getDOM().parent().show();
			return this;
		},
		hide: function(){
			this.Super('hide', arguments);
			this.getDOM().parent().hide();
			return this;
		},
		// 渲染结果描述
		renderResultDesc: function(value){
			var self = this;
			var c = self.getConfig();
			var html = [
				'<label>',
					c.title,
					'<span>',
						value && value.name || '',
					'</span>',
				'</label>'
			].join('');

			// 是否比较默认值
			if(c.compareValue){
				return value.id == c.value ? '' : html;
			}else{
				return !value.id ? '' : html;
			}
		}
	});
	exports.radio = SideBarRadio;

	// 侧栏多选形式基类
	var SideBarCheckbox = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio M-sidebarCheckbox',
				'title': '',
				'data': null, // 选中的选项
				'key': 'id', // 选项记录关键字字段名
				'name': 'name', // 选项记录显示字段名
				'value': '', // 默认值
				'selected': [],
				'view_model': {
					'data': [],
					'value': '',
					'selected': []
				}
			});

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			util.each(c.data, function(item){
				if(item){
					item.id = item[c.key];
					item.name = item[c.name];
					item.checked = item.checked || false;
				}
			});

			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;


			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
					'</div>',
				'</div>'
			].join('')));

			// 构建checkbox组
			self.createAsync('checkboxGroup', '@base/common/input.checkbox', {
				'data': self.vm.getItem('data'),
				'key': 'id',
				'name': 'name',
				'changeEvent': true,
				'autoChange': false,
				'target': el.find('.group-content')
			}, function(mod){
				if(mod){
					mod.reset();
					mod.setData(c.selected);
				}
			});

		},
		onCheckboxChange: function(ev){

			var self = this;
			if(ev.param){
				var selected = ev.param.selected || [];
				var result = [];
				var data = util.clone(self.vm.getItem('data'));

				// 结果集，具体看checked属性
				util.each(data, function(item){
					item.checked = false;
					util.each(selected, function(sel){
						if(item.id == sel){
							item.checked = true;
						}
					});
					result.push(item);
				});

				self.fire('sidebarFilterGroup', {
					type: self._.name,	//子模块名
					data: result,	// 选中值
					value: ev.param.checked,
					id: ev.param.id || null,
					selected: selected, // 已选id组
					desc: self.renderResultDesc(result, selected) // 描述
				});
			}
		},
		// 渲染结果描述
		renderResultDesc: function(result, selected){
			var self = this;
			var c = self.getConfig();
			var name = [];
			util.each(result, function(item){
				if(item && item.name && item.checked){
					name.push(item.name);
				}
			});
			var html = [
				'<label>',
					c.title,
					'<span>',
						name.join('；'),
					'</span>',
				'</label>'
			].join('');
			return !selected.length ? '' : html;
		},
		reset: function(){
			var self = this;
			if(self.$.checkboxGroup){
				self.$.checkboxGroup.reset().eventCheckboxChange({
					data: {}
				});
			}
			return self;
		}
	});
	exports.checkbox = SideBarCheckbox;

	// 新渠道选项
	var Channel = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio',
				'title': LANG('渠道：'),
				'autoFire': false,	// 设置了value的时候，一开始是否发送广播
				'hasAllChannel': true, // 是否有所有渠道
				'channel': [],	// 渠道配置
				'monitorUrl': 'adSubChannel/list',
				'filterAccess': false,
				'data': null, // 选中的选项
				'key': 'id', // 选项记录关键字字段名
				'name': 'name', // 选项记录显示字段名
				'value': '', // 默认值
				'defaultLimit': 18, // 默认要显示的个数
				'view_model': {
					'data': [],
					'value': '',
					'channel': [], // 循环用渠道分类数组
					'defaultLimit': 18, // 默认要显示的个数
					'moreLimit': 18, // 显示更多的个数
					'moreText': LANG('更多...'),
					'moreTextDown': LANG('更多...'),
					'moreTextUp': LANG('收起↑'),
					'moreClick': this.eventMoreClick
				}
			});

			// 当前模式
			this.$mode = 0;
			// pc+移动渠道合集，监测渠道需要另外拉取
			this.$allExchange = util.clone(pubjs.config('exchange'));
			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			self.vm.$.value = c.value;
			self.vm.$.defaultLimit = +c.defaultLimit;
			self.vm.$.moreLimit = +c.defaultLimit;

			// 构建DOM
			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div class="M-sidebarRadioCon">',
							'<div class="M-sidebarDropCon ml5 mb15">',
							'</div>',
							'<div class="M-sidebarChannelCon" ms-each-option="channel">',
								'<div ms-data-channel="option.id" ms-visible="$index==0">',
									'<div ms-repeat-item="option.data" class="content text-truncate" ms-visible="$index<moreLimit" ms-data-id="item.id">',
										'<label class="cur_p" ms-class="act:value==item.id" title="">',
											'<input ms-value="item.id" type="radio" ms-duplex-text="value" ms-visible="false">',
											'<i class="icon-circle-double icon-circle-thin mr5" ms-visible="true" ms-class="icon-circle-thin:value!=item.id"/>',
											'{{item.name}}',
										'</label>',
									'</div>',
									'<div class="more" ms-click="moreClick()" ms-visible="defaultLimit<option.data.length" ms-text="moreText"></div>',
								'</div>',
							'</div>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			// 监测改变
			self.vm.watch('value', self.eventRadioChange);

			// 加入所有渠道
			if(c.hasAllChannel){
				self.$allExchange.unshift({
					name: LANG('所有渠道'),
					id: 0
				});
				c.channel.unshift({title: LANG('全部'), data: self.$allExchange, id: 0});
			}
			self.vm.$.channel = c.channel || [];


			// 加载监测渠道
			self.loadMonitorChannel();

			// 构建下拉
			self.createAsync('drop', '@base/common/drop.drop', {
				'type': 'text',
				'addClass': 'simple',
				'options': self.$allExchange,
				'target': el.find('.M-sidebarDropCon'),
				'placeholder': LANG('全部'),
				'keyupShowPanel': true,
				'hasCancelBtn': true,
				'panel_config': {
					'hasSearch': false,
					'height': 200
				}
			});

			// 根据配置手动触发变化
			if(c.autoFire){
				this.eventRadioChange();
			}
		},
		onDropChange: function(ev){
			var self = this;

			if(ev.param.id){
				// 选定值
				self.vm.$.value = ev.param.id;
				self.fire('sidebarEnter');
			}
			return false;
		},
		loadMonitorChannel: function(){
			if(pubjs.checkRight('spot.monitorList')){
				var c = this.getConfig();
				if(c.monitorUrl){
					pubjs.mc.send(c.monitorUrl, this.onLoadMonitorChannel.bind(this));
				}
			}
		},
		onLoadMonitorChannel: function(err, data){
			if (err){
				pubjs.log(err.message);
				return false;
			}
			// 加入广告监测渠道
			if(data && data.items){
				var self = this;
				var c = self.getConfig();
				c.channel.push({'title': LANG('广告监测'),'data': data.items,'id': 2});

				// 更新所有渠道
				self.$allExchange = self.$allExchange.concat(data.items);
				var all = util.find(c.channel, 0, 'id');
				if(all){
					all.data = self.$allExchange;
				}

				self.vm.$.channel = c.channel;

				if(self.$.drop){
					self.$.drop.setData(self.$allExchange);
				}
				//当手动传入mode为2
				if(c.mode == 2){
					this.setActive(2);
				}

			}
		},
		eventRadioChange: function(value) {
			var self = this;
			var id = self.vm.$.value;
			var item = util.find(self.$allExchange, id, 'id');

			self.fire('sidebarFilterGroup', {
				type: self._.name,	//子模块名
				data: [item],	//值集合
				value: item ,	//值对象
				id: item && item.id || '',	//id
				desc: self.renderResultDesc(+id, item)
			});
		},
		eventMoreClick: function(){
			var vm = this.vm.$;
			if(vm.moreLimit > vm.defaultLimit) {
				vm.moreLimit = vm.defaultLimit;
				vm.moreText = vm.moreTextDown;
			}else{
				vm.moreLimit = this.$allExchange.length;
				vm.moreText = vm.moreTextUp;
			}

			return false;
		},
		setActive: function(mode){
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM();
			var childrens = el.find('.M-sidebarChannelCon').find('>div');
			var child = childrens.hide().filter('[data-channel="'+mode+'"]').show();
			// 将所有渠道插入到当前项的最前面
			childrens.find('div[data-id="0"]').prependTo(child);

			// 更新下拉数据
			var item = util.find(c.channel, mode, 'id');
			if(self.$.drop){
				self.$.drop.setData(item && item.data || []);
				self.$.drop.reset();
			}
			// 更新mode
			self.$mode = mode;
			return self;
		},
		setValue: function(value){
			this.vm.$.value = value;
			return this;
		},
		setAll: function(){
			this.vm.$.value = '';
			return this;
		},
		getAllExchange: function(){
			return this.$allExchange;
		},
		reset: function(){
			//this.vm.reset();
			var self = this;
			var c = self.getConfig();
			self.vm.$.value = c.value;

			// mode等于0时，只设置drop的reset
			if(self.$mode){
				self.setActive(0);
			}else{
				if(self.$.drop){
					self.$.drop.reset();
				}
			}

			return self;
		},
		// 响应活动类型变化
		onCampaignTypeChange: function(ev){
			this.setActive(+ev.param);
			return false;
		},
		// 响应活动类型变化
		onAgentTypeChange: function(ev){
			this.setActive(ev.param);
			return false;
		},
		renderResultDesc: function(id, value){
			var self = this;
			var exchange = self.$allExchange;
			var channel = util.find(exchange, id, 'id');

			var c = self.getConfig();
			var html = [
				'<label>',
					c.title,
					'<span>',
						channel && channel.name || '',
					'</span>',
				'</label>'
			].join('');

			// 是否比较默认值
			if(c.compareValue){
				return id == c.value ? '' : html;
			}else{
				return !id ? '' : html;
			}
		}
	});
	exports.channel = Channel;

	// 标签过滤-新标签组
	var Label = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio M-sidebarLabel',
				'title': LANG('标签：'),
				'url': 'whisky/labels',	// 请求地址
				'data': null, // 选中的选项
				'key': 'id', // 选项记录关键字字段名
				'name': 'name', // 选项记录显示字段名
				'value': '', // 默认值
				'defaultLimit': 8, // 默认要显示的个数
				'view_model': {
					'data': [],
					'value': '',
					'selected': [],
					'itemClick': this.eventItemClick,
					'defaultLimit': 8, // 默认要显示的个数
					'moreLimit': 8, // 显示更多的个数
					'moreText': LANG('更多...'),
					'moreTextUp': LANG('收起↑'),
					'moreClick': this.eventMoreClick
				}
			});

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			util.each(c.data, function(item){
				if(item){
					item.id = item[c.key];
					item.name = item[c.name];
				}
			});

			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;
			self.vm.$.defaultLimit = +c.defaultLimit;
			self.vm.$.moreLimit = +c.defaultLimit;

			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div class="content text-truncate" data-type="all">',
							'<label class="cur_p check" ms-class="check:!selected.length">',
								LANG('全部'),
							'</label>',
						'</div>',
						'<div ms-repeat-item="data" class="content text-truncate" ms-visible="$index<moreLimit">',
							'<label class="cur_p" ms-class="check:item.checked">',
								'<input ms-value="item.name" type="checkbox" ms-duplex="selected" ms-visible="false" ms-click="itemClick(item)">',
								'{{item.name}}',
								'<span class="count">({{item.count}})</span>',
							'</label>',
						'</div>',
						'<div class="more" ms-click="moreClick()" ms-visible="defaultLimit<data.length" ms-text="moreLimit==data.length?moreTextUp:moreText"></div>',
					'</div>',
				'</div>'
			].join('')));


			if(c.url){
				self.loadLabel();
			}

			self.uiBind(el.find('[data-type="all"]'), 'click', 'eventAllClick');

			// 监听值变化，发送事件
			self.vm.watch('selected/length', function(){

				var selected = self.vm.getItem('selected');
				var result = [];
				util.each(selected, function(sel){
					result.push(util.find(self.vm.getItem('data'), sel, 'name'));
				});

				self.fire('sidebarFilterGroup', {
					type: self._.name,	//子模块名
					data: [result],	//值集合
					value: result,	//值对象
					id: selected.join(',') || '',	//id
					desc: self.renderResultDesc && self.renderResultDesc(selected.join(','))
				});

			});
		},
		loadLabel: function(){
			//pubjs.loading.show(this.getDOM());
			var c = this.getConfig();
			pubjs.mc.send(c.url, this.onLoadLabel.bind(this));
		},
		onLoadLabel: function(err, data){
			//pubjs.loading.hide();
			if (err){
				pubjs.alert(err.message);
				return false;
			}
			// 加入广告监测渠道
			if(data && data.items){

				util.each(data.items, function(item){
					if(item){
						item.checked = false;
					}
				});
				this.vm.$.data = data.items;
			}
		},
		eventAllClick: function(evt, elm){
			var self = this;
			var data = self.vm.$.data;
			util.each(data, function(item, idx){
				if(item){
					item.checked = false;
				}
			});
			self.vm.$.selected = [];

			self.fire('sidebarFilterGroup', {
				type: self._.name,	//子模块名
				data: [],	//值集合
				value: '',	//值对象
				id: '',	//id
				desc: self.renderResultDesc && self.renderResultDesc('')
			});
			return false;
		},
		eventItemClick: function(item){
			// 修改样式
			item.checked = !item.checked;
			return false;

		},
		eventMoreClick: function(){
			var vm = this.vm.$;
			if(vm.moreLimit > vm.defaultLimit){
				vm.moreLimit = vm.defaultLimit;
			}else{
				vm.moreLimit = vm.data.length;
			}
			return false;
		},
		onDeleteFilter: function(ev){
			if(ev.param){
				var deleteValue = ev.param.deleteValue;
				var data = this.vm.$.data;
				var value = ev.param.value;
				var selected  = this.vm.$.selected;

				// 删除后更新状态
				util.each(data, function(item, idx){
					if(item && item.name == deleteValue.name){
						item.checked = false;
						selected.splice(idx, 1);
					}
				});

				// 如果没有选中值，默认回全部
				if(!value){
					this.vm.$.selected = [];
				}
			}

			return false;
		},
		reset: function(){
			// this.vm.reset();
			this.eventAllClick(null);
			return this;
		},
		renderResultDesc: function(id, value){
			var self = this;
			var c = self.getConfig();
			var label = id && id.replace(/,/ig, '；');
			var html = [
				'<label>',
					c.title,
					'<span>',
						label || '',
					'</span>',
				'</label>'
			].join('');

			return !id ? '' : html;
		}
	});
	exports.label = Label;

	// 新指标过滤-指标组
	var Metrics = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio M-sidebarMetrics',
				'title': LANG('高级：'),
				'data': null, // 选中的选项
				'value': '', // 默认值
				'metrics': null,
				'view_model': {
					'data': [],
					'value': ''
				}
			});

			this.$curData = null;

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			util.each(c.data, function(item){
				if(item){
					item.id = item[c.key];
					item.name = item[c.name];
				}
			});

			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;

			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div class="metricsCon"></div>',
						'<div class="button" ms-visible="false">',
							'<input type="button" class="btn btn-confirm" value="'+LANG('搜索')+'"/>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			self.create('metricsFilter', MetricsFilter, {
				target: el.find('.metricsCon'),
				metrics: c.metrics
			});

			self.uiBind(el.find('.button input'), 'click', 'eventButtonClick');

			// self.$watchMetricsChange = setInterval(function(){
			// 	self.eventButtonClick(null);
			// }, 200);
		},
		eventButtonClick: function(evt, elm){
			var self = this;
			if(self.$.metricsFilter){
				var data  = self.$.metricsFilter.getValue();
				if(self.$curData == data){
					return false;
				}else{
					self.$curData = data;
				}

				var value = [];
				util.each(data, function(item){
					if(item && item.data){
						value.push(item.data);
					}
				});

				var id = JSON.stringify(value);

				self.fire('sidebarFilterGroup', {
					type: self._.name,	//子模块名
					data: [value],	//值集合
					value: value,	//值对象
					id: id || '',	//id
					desc: self.renderResultDesc && self.renderResultDesc(id, value)
				});
			}
		},
		onDeleteFilter: function(ev){
			if(ev.param){
				if(this.$.metricsFilter){
					this.$.metricsFilter.removeItem(ev.param.modName);
				}
			}

			return false;
		},
		getMetrices: function(){
			if(this.$.metricsFilter){
				return this.$.metricsFilter.getMetrices();
			}
			return [];
		},
		onSidebarSave: function(){
			this.eventButtonClick(null);
		},
		reset: function(){
			if(this.$.metricsFilter){
				this.$.metricsFilter.reset();
			}
			return this;
		},
		renderResultDesc: function(id, value){
			var self = this;
			var metrics = self.getMetrices(); // 获取指标集
			var group = [];
			var result = JSON.parse(id); // 转化指标的条件
			if(result && result.length){
				util.each(result, function(item){
					if(item){
						var metric = util.find(metrics, item.factor, 'id');
						if(metric && metric.name){
							group.push(metric.name + ' ' + item.sign + ' ' + item.value);
						}
					}
				});
			}

			var c = self.getConfig();
			var html = [
				'<label>',
					c.title,
					'<span>',
						group.join('、'),
					'</span>',
				'</label>'
			].join('');

			return (result && result.length) === 0 ? '' : html;
		}
	});
	exports.metrics = Metrics;

	// 指标过滤-指标组-指标区域
	var MetricsFilter = view.container.extend({
		init: function(config) {
			config = pubjs.conf(config, {
				// 指标配制，null时为config.js中default_tab_cols的全部指标
				// {name}对应default_tab_cols中的一个指标组
				// demo: ['back_pageviews',"{conversion}"]
				'metrics': null,
				// 最少项
				'min': 0,
				// 最多项
				'max': 10,
				// 上次getValue的数据
				'value': null,
				'class': 'M-sidebarMetricsFilter'
			});

			this.$items = [];
			this.$reg = /^\{(\w+)\}$/;
			this.$prefix = 'FILTER_CHILD_';
			this.$operators = [
				{id: '>', name: '>'},
				{id: '<', name: '<'},
				{id: '=', name: '='}
			]
			this.$metrices = this.initMetricesOptions(config);

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);
			var value = c.value;

			$([
				'<div class="con"/>',
				'<span class="addBtn">'+LANG('添加条件')+'</span>'
			].join('')).appendTo(el);

			var doms = self.$doms = {
				con: el.find('>.con'),
				addBtn: el.find('>.addBtn')
			}

			self.uiBind(doms.addBtn, 'click', 'eventAddItem');

			if (value && value.length) {
				self.empty();
				util.each(value, function(item) {
					self.addItem(item.data);
				});
			} else {
				self.reset();
			}
		},
		// 初始化指标dropdown选项
		initMetricesOptions: function(config) {
			var self = this;
			var metrics = config.get('metrics');
			var all = pubjs.config('defaultGroup');
			var map = {};
			var keys = [];
			var options = [];

			// 将所有指标名放入keys中
			if (metrics) {
				util.each(metrics, function(item) {
					var matches = String(item).match(self.$reg);

					if (matches && matches[1] && all &&all[matches[1]]) {
						keys.push.apply(keys, all[matches[1]].cols || []);
					} else {
						keys.push(item);
					}
				});
			} else {
				util.each(all, function(tab) {
					keys.push.apply(keys, tab.cols || []);
				});
			}

			// 去重，并获取文案
			util.each(keys, function(key) {
				var cfg;
				if (!(key in map)) {
					map[key] = 1;
					cfg = labels.has(key) && labels.get(key);
					if (cfg && cfg.text) {
						options.push({
							id: key,
							name: cfg.text
						});
					}
				}
			});
			return options;
		},
		eventAddItem: function(ev){
			this.addItem();
			return false;
		},
		addItem: function(data) {
			var self = this;
			var doms = self.$doms;
			var max = self.getConfig('max');
			if (self.$items.length >= max) {
				pubjs.alert(LANG("最多只允许添%1加个选项", max));
				return false;
			}

			var name = self.$prefix + util.guid();
			var cont = $('<div class="mb10 clear" />').appendTo(doms.con);
			var metric = self.create('metric' + name, drop.drop, {
				'key': 'id',
				'name': 'name',
				'width': 150,
				'addClass': 'mr5 fl',
				'target': cont,
				'options': self.$metrices,
				'value': self.$metrices && self.$metrices[0] && self.$metrices[0].id,
				'panel_config': {
					'height': 120,
					'appendTo': 'relative'
				}
			});
			var operate = self.create('operate' + name, drop.drop, {
				'key': 'id',
				'name': 'name',
				'width': 80,
				'addClass': 'mr5 fl',
				'target': cont,
				'hasSearch': false,
				'options': self.$operators,
				'value': '>',
				'panel_config': {
					'appendTo': 'relative'
				}
			});
			var value = $('<input class="mr15 fl ml5" type="text" placeholder="0" />').appendTo(cont).width(80).css('max-height', 30);
			var removeBtn = $('<span class="removeBtn"><i class="icon-close"/></span>').appendTo(cont);

			self.uiBind(removeBtn, 'click', name, 'evRemoveBtnClick');


			if (data) {
				metric.setValue(data['factor']);
				operate.setValue(data['sign']);
				value.val(data['value']);
			}

			self.$items.push({
				name: name,
				cont: cont,
				metric: metric,
				operate: operate,
				value: value,
				removeBtn: removeBtn
			});
			self.itemChange();
			return true;
		},
		removeItem: function(name) {
			if (!name) {
				return;
			}
			var items = this.$items;
			var item = util.find(items, name, 'name');
			if (item) {
				this.uiUnbind(item.removeBtn, 'click');
				item.metric.destroy();
				item.operate.destroy();
				item.cont.remove();
				util.remove(items, name, 'name');
				this.itemChange();
			}
		},
		itemChange: function() {
			var count = this.$items.length;
			var c = this.getConfig();
			util.each(this.$items, function(item, index) {
				// 超过最低限制时才显示删除按钮
				item.removeBtn.css('visibility', count > c.min ? 'visible': 'hidden');
			});
		},
		evRemoveBtnClick: function(evt) {
			var name = evt.data;
			this.removeItem(name);
			return false;
		},
		// 清空所有
		empty: function() {
			var self = this;
			var len = self.$items.length;
			for(var i=0; i<len; i++){
				self.removeItem(self.$items[0].name);
			}
			return self;
		},
		reset: function() {
			this.empty();
			for (var i = 0; i < this.getConfig('min'); i++) {
				this.addItem();
			}
			return this;
		},
		onDropChange: function(ev){
			return false;
		},
		getValue: function() {
			var self = this;
			var data = [];
			util.each(self.$items, function(item) {
				if(item){
					// 检测用户输入是否非数字
					var val = +item.value.val() || 0;
					var metric = item.metric.getValue(true);
					var operate = item.operate.getValue('id');
					data.push({
						'id': util.guid(),
						'text': metric.name + operate + val,
						'name': metric.name + operate + val,
						'modName': item.name,
						'data': {
							'factor': metric.id,
							'sign': operate,
							'value': val
						}
					});
				}
			});
			return data || false;
		},
		getMetrices: function(){
			return this.$metrices || [];
		}
	});
	exports.metricsFilter = MetricsFilter;

	// 新列表过滤-指标组
	var GridGroup = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio M-sidebarMetrics M-sidebarGrid',
				'title': LANG('列表过滤：'),
				'url': '',
				'data': null, // 选中的选项
				'value': '', // 默认值
				'metrics': null,
				'nameField': '',
				'view_model': {
					'data': [],
					'value': ''
				}
			});

			this.$data = {};
			this.$selectedIds = [];

			this.Super('init', arguments);
		},
		afterBuild: function() {

			var self = this;

			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			util.each(c.data, function(item){
				if(item){
					item.id = item[c.key];
					item.name = item[c.name];
				}
			});

			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;

			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div class="metricsCon"></div>',
						'<div class="button" ms-visible="false">',
							'<input type="button" class="btn btn-confirm" value="'+LANG('搜索')+'"/>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			self.create('gridFilter', grid.baseNoDate, {
				'hasSearch': true,
				'hasSubGrid': false,
				'hasExport': false,
				'hasAmount': false,
				'hasTab': false,
				'hasSelect': true,
				'reqType': 'websocket',
				// 'nameField': 'Name',
				'pager': {
					'size': 8,
					'bounds': 4,
					'showSizeTypes': false,
					'showJumper': false
				},
				'url': c.url,
				'cols': [
					{name:'_id',text:"ID", sort: true, align: 'center'},
					{name:'Name',text:LANG("名称"), type:'index', width: 400, render: this.renderName}
				],
				'list':{
					'rowSelect': true,
					'scroll_type': 'row',
					'scroll_size': 5
				},
				'target': el.find('.metricsCon')
			});

			self.uiBind(el.find('.button input'), 'click', 'eventButtonClick');
		},
		renderName: function(i, val, data, con) {
			return $('<div class="text-truncate" title="' + val + '">' + val + '</div>').width(con.width);
		},
		// 选中消息
		onChangeSelect: function(ev) {
			var c = this.getConfig();
			var data = this.$data;
			util.each(ev.param.data, function(item, idx){
				data[item._id] = {
					'id': item._id,
					'name': item[c.nameField || 'Name']
				};
			});
			return false;
		},
		getData: function(){
			var result = [];
			var ids = this.$selectedIds = this.$.gridFilter.getSelectRowIds();
			var data = this.$data;
			util.each(ids, function(id, idx){
				if(data[id]){
					result.push(data[id]);
				}
			});
			return result;
		},
		eventButtonClick: function(evt, elm){
			var self = this;
			if(self.$.gridFilter){
				var data = self.getData();
				var value = [];
				util.each(data, function(item){
					if(item && item.id){
						value.push(item.id);
					}
				});

				var id = JSON.stringify(value);

				self.fire('sidebarFilterGroup', {
					type: self._.name,	//子模块名
					data: [value],	//值集合
					value: value,	//值对象
					id: id || '',	//id
					desc: self.renderResultDesc && self.renderResultDesc(id, value)
				});
			}
		},
		onDeleteFilter: function(ev){
			if(ev.param){
				if(this.$.gridFilter){
					var id = ev.param.deleteValue && ev.param.deleteValue.id || null;
					var index;
					util.each(this.$selectedIds, function(item, idx){
						if(item == id){
							index = idx;
						}
					});

					this.$selectedIds.splice(index, 1);
					this.$.gridFilter.setSelectRowIds(this.$selectedIds);
				}
			}
			return false;
		},
		onSidebarSave: function(){
			this.eventButtonClick(null);
		},
		reset: function(){
			// this.$data = {};
			// this.$selectedIds = [];
			// this.vm.reset();
			if(this.$.gridFilter){
				this.$.gridFilter.setSelectRowIds([]);
			}
			return this;
		},
		renderResultDesc: function(id, value){
			var self = this;
			var c = self.getConfig();
			var result = JSON.parse(id);

			var html = [
				'<label>',
					c.title,
					'<span>',
						result.join('、'),
					'</span>',
				'</label>'
			].join('');

			return (result && result.length) === 0 ? '' : html;
		}
	});
	exports.gridGroup = GridGroup;

	// 广告主过滤模块
	var AderGridGroup = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio M-sidebarMetrics M-sidebarGrid',
				'title': LANG(''),
				'url': '',
				'data': null, // 选中的选项
				'value': '', // 默认值
				'view_model': {
					'data': [],
					'value': ''
				}
			});

			this.$data = {};
			this.$selectedIds = [];

			this.Super('init', arguments);
		},
		afterBuild: function() {

			var self = this;

			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			util.each(c.data, function(item){
				if(item){
					item.id = item[c.key];
					item.name = item[c.name];
				}
			});

			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;

			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div class="metricsCon"></div>',
						'<div class="button" ms-visible="false">',
							'<input type="button" class="btn btn-confirm" value="'+LANG('搜索')+'"/>',
						'</div>',
					'</div>',
				'</div>'
			].join('')));

			self.create('gridFilter', grid.baseNoDate, {
				'hasSearch': true,
				'hasSubGrid': false,
				'hasExport': false,
				'hasAmount': false,
				'hasTab': false,
				'hasSelect': true,
				'reqType': 'websocket',
				// 'nameField': 'Name',
				'param': {
					'order': 'CreateTime|-1'
				},
				'pager': {
					'size': 8,
					'bounds': 4,
					'showSizeTypes': false,
					'showJumper': false
				},
				'url': 'qualification/list',
				'cols': [
					{name:'_id',text:"ID", sort: true, render: 'center',align: "center"},
					{name:'UserName',text:LANG("名称"), type:'index', width: 400, render: this.renderName,align: "center"}
				],
				'list':{
					'rowSelect': true,
					'scroll_type': 'row',
					'scroll_size': 5
				},
				'target': el.find('.metricsCon')
			});

			self.uiBind(el.find('.button input'), 'click', 'eventButtonClick');
		},
		renderName: function(i, val, data, con) {
			return $('<div class="text-truncate" title="' + data.UserName + '">' + data.UserName + '</div>').width(con.width);
		},
		// 选中消息
		onChangeSelect: function(ev) {
			var c = this.getConfig();
			var data = this.$data;
			util.each(ev.param.data, function(item, idx){
				data[item._id] = {
					'id': item._id,
					'name': item[c.nameField || 'UserName']
				};
			});
			return false;
		},
		getData: function(){
			var result = [];
			var ids = this.$selectedIds = this.$.gridFilter.getSelectRowIds();
			var data = this.$data;
			util.each(ids, function(id, idx){
				if(data[id]){
					result.push(data[id]);
				}
			});
			return result;
		},
		eventButtonClick: function(evt, elm){
			var self = this;
			if(self.$.gridFilter){
				var data = self.getData();
				var value = [];
				var ids = [];
				util.each(data, function(item){
					if(item && item.name){
						value.push(item.name);
						ids.push(item.id);
					}
				});

				var name = JSON.stringify(value);

				self.fire('sidebarFilterGroup', {
					type: self._.name,	//子模块名
					data: ids,	//值集合
					value: value,	//值对象
					name: name || '',	//name
					desc: self.renderResultDesc && self.renderResultDesc(name, value)
				});
			}
		},
		onDeleteFilter: function(ev){
			if(ev.param){
				if(this.$.gridFilter){
					var id = ev.param.deleteValue && ev.param.deleteValue.id || null;
					var index;
					util.each(this.$selectedIds, function(item, idx){
						if(item == id){
							index = idx;
						}
					});

					this.$selectedIds.splice(index, 1);
					this.$.gridFilter.setSelectRowIds(this.$selectedIds);
				}
			}
			return false;
		},
		onSidebarSave: function(){
			this.eventButtonClick(null);
		},
		renderResultDesc: function(name, value){
			var self = this;
			var c = self.getConfig();
			var result = JSON.parse(name);

			var html = [
				'<label>',
					c.title,
					'<span>',
						result.join('、'),
					'</span>',
				'</label>'
			].join('');

			return (result && result.length) === 0 ? '' : html;
		},
		reset: function(){
			// this.$data = {};
			// this.$selectedIds = [];
			// this.vm.reset();
			if(this.$.gridFilter){
				this.$.gridFilter.setSelectRowIds([]);
			}
			return this;
		}
	});
	exports.aderGridGroup = AderGridGroup;

	// ads分组过滤
	var AdsGroupPop = SideBarRadio.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'title': LANG('分组：'),
				'url': 'adsGroup/list',
				'key': '_id', // 选项记录关键字字段名
				'name': 'Name', // 选项记录显示字段名,
				'param': {
					'ChannelId': pubjs.config('pcChannel')[0].id
				},
				'all': true,
				'value': 0
			});

			this.Super('init', arguments);
		}
	});
	exports.adsGroupPop = AdsGroupPop;

	// 活动类型模块
	var CampaignType = SideBarRadio.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'title': LANG('类型：'),
				'data': [
					{id: 0, name: LANG('所有活动')},
					{id: 1, name: LANG('PC广告')},
					{id: 4, name: LANG('移动广告')}
				],
				'value': 0
			});

			var type = config.get('type');
			var right = 'spotMonitor.listCampaign';
			if(type == 'spot')
			{
				right = 'spot.monitorList';
			}
			else if(type == 'campaign')
			{
				right = 'spotMonitor.listCampaign';
			}

			if(right && pubjs.checkRight(right))
			{
				var data = config.get('data');
				data.push({id: 2, name: LANG('广告监测')});
			}

			this.Super('init', arguments);
		},
		afterBuild: function()
		{
			this.Super('afterBuild', arguments);
			var c = this.getConfig();
			if(c.data.length === 1)
			{
				this.eventRadioChange(c.data[0].id);
				this.hide();
			}
			if(c.data.length === 3)
			{
				this.eventRadioChange(c.data[0].id);
			}
		},
		eventRadioChange: function(value) {
			this.Super('eventRadioChange', arguments);
			// 通过父级下发广播到下级，让渠道pops变化
			this.parent().cast('campaignTypeChange', value);
		}
	});
	exports.campaignType = CampaignType;

	// 广告渠道类型选择
	exports.agentType = SideBarRadio.extend({
		init:function(config){
			config = pubjs.conf(config, {
				title: LANG('类型：'),
				data: [
					{id: 0, name: LANG('全部')},
					{id: 'pc', name: LANG('PC')},
					{id: 'android', name: LANG('APP-Android')},
					{id: 'ios', name: LANG('APP-iOS')}
				],
				value: 0
			});

			this.Super('init', arguments);
		},
		eventRadioChange: function(value) {
			this.Super('eventRadioChange', arguments);
			// 通过父级下发广播到下级，让渠道pops变化
			this.parent().cast('agentTypeChange', value);
		}
	});

	// 消费模块
	var CostType = SideBarRadio.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'title': LANG('系统扣费：'),
				'data': [
					{id: 0, name: LANG('所有')},
					{id: 1, name: LANG('扣费')},
					{id: 2, name: LANG('不扣费')}
				],
				'value': 0
			});

			this.Super('init', arguments);
		},
		onCampaignTypeChange: function(ev){
			var id = +ev.param;
			this[id == 2 ? 'show' : 'hide']().setValue(0);
		}
	});
	exports.costType = CostType;

	// 推广组的radio加label模块
	var SideBarDealRadio = SideBarRadio.extend({
		init: function(config){
			config = pubjs.conf(config, {
				select_config: {
					url: 'deal/list',
					name: LANG('添加筛选订单'),
					grid_mod: 'campaign/modules/select.dealGrid',
					gridTitle: LANG('选择订单')
				},
				view_model: {
					// 是否显示添加筛选订单的按钮
					'isShowDeal': false
				}
			});

			this.$ids = [];
			this.Super('init', arguments);
		},
		afterBuild: function(){
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			if(c.data && c.data.length) {
				self.setKey(c.data);

				if(c.all){
					c.data.unshift(c.all_item);
				}
			}

			self.vm.$.data = c.data || [];
			self.vm.$.value = c.value;
			self.vm.$.defaultLimit = +c.defaultLimit;
			self.vm.$.moreLimit = +c.defaultLimit;

			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
						'<div ms-each-item="data" class="content">',
							'<label class="" ms-class="act:value==item.id" ms-if="item" ms-visible="$index<moreLimit">',
								'<input ms-value="item.id" type="radio" ms-duplex-text="value" ms-visible="false">',
								'<i class="icon-circle-double icon-circle-thin mr5" ms-visible="true" ms-class="icon-circle-thin:value!=item.id"/>',
								'{{item.name}}',
							'</label>',
						'</div>',
					'</div>',
				'</div>',
				'<div ms-visible="isShowDeal" pub-name="labelSelect" pub-mod="campaign/modules/select.main"/>'
			].join('')));

			self.vm.watch('value', self.eventRadioChange);

			if(c.url){
				self.load();
			}

			self.buildFromTemplate({
				labelSelect: self.getConfig('select_config')
			});
		},
		eventRadioChange: function(value){
			var vm = this.vm.$;

			if (+value === 1)
			{
				if (this.$ids && this.$ids.length)
				{
					vm.isShowDeal = true;
				}
				else
				{
					this.$.labelSelect.showSelect();
				}
	 		}
			else {
				vm.isShowDeal = false;
			}

			return false;
		},
		reset: function(){
			this.Super('reset', arguments);
			var cs = this.$;
			cs.labelSelect.reset();

			return this;
		},
		renderResultDesc: function(value){
			var self = this;
			var title = LANG('订单：');
			var label = value && value.join('；');
			var html = [
				'<label>',
					title,
					'<span>',
						label || '',
					'</span>',
				'</label>'
			].join('');

			return (value && value.length) ? html : '';
		},
		onSelectChange: function(ev){
			var self = this;
			var c = this.getConfig();
			var param = ev.param;
			var name = param.name;
			this.$ids = param.new || [];
			this.checkStatus();

			if(param) {
				this.fire('sidebarFilterGroup', {
					type: this._.name,	//子模块名
					data: param.new,	//值集合
					// value: value,	//值对象
					// id: value.id || '',	//id
					desc: self.renderResultDesc(name)
				});
			}
		},
		onSelectCancel: function(ev){
			this.checkStatus();
		},
		checkStatus: function()
		{
			var showDeal = !!(this.$ids && this.$ids.length);
			this.vm.$.isShowDeal = showDeal;
			this.setValue(showDeal ? 1 : 0);
		}
	});

	exports.dealRadio = SideBarDealRadio;

	exports.qualificationRadio = SideBarDealRadio.extend({
		renderResultDesc: function(value){
			var self = this;
			var title = LANG('资质：');
			var label = value && value.join('；');
			var html = [
				'<label>',
					title,
					'<span>',
						label || '',
					'</span>',
				'</label>'
			].join('');

			return (value && value.length) ? html : '';
		}
	});

	// 侧栏下拉形式基类
	var SideBarDrop = view.container.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'class': 'M-sidebarRadio M-sidebarDrop',
				'title': '',
				'url': '',
				'compareValue': false,
				'dropType': 'button', // 类型: button | text | multi
				'drop_config': {}
			});

			this.Super('init', arguments);
		},
		afterBuild: function() {
			var self = this;
			var c = self.getConfig();
			var el = self.getDOM().addClass(c.class);

			el.append($([
				'<div class="M-formConGroup M-sidebarRadioCon">',
					'<div class="group-label title">',
						'<label>' + c.title + '</label>',
					'</div>',
					'<div class="group-content">',
					'</div>',
				'</div>'
			].join('')));


			self.create('drop', drop.drop, util.extend({
				'target': el.find('.group-content'),
				'reqType': 'websocket', // ajax | websocket
				'url': c.url,
				'panel_config': {
					'height': 200
				}
			}, c.drop_config));
		},
		onDropChange: function(ev){

			var self = this;
			var c = self.getConfig();
			var drop_config = c.drop_config;
			var data = self.$.drop.getValue(true);
			var ids = self.$.drop.getValue();

			if(c.dropType != 'multi' && !drop_config.hasChild){
				data = [data];
				var id_tmp = self.$.drop.getValue('id');
				if(id_tmp){
					ids = [id_tmp];
				}
			}

			var id = ev && ev.param && ev.param.id || null;

			if(data){
				self.fire('sidebarFilterGroup', {
					type: self._.name,	//子模块名
					data: data,	// 选中值
					value: id,
					id: id,
					selected: ids, // 已选id组
					desc: self.renderResultDesc(data, ids || []) // 描述
				});
			}
		},
		onSidebarSave: function(){
		},
		// 渲染结果描述
		renderResultDesc: function(result, selected){
			var self = this;
			var c = self.getConfig();
			var drop_config = c.drop_config;
			var name = [];
			util.each(result, function(item){
				if(item && item[drop_config.name]){
					name.push(item[drop_config.name]);
				}
			});
			var html = [
				'<label>',
					c.title,
					'<span>',
						name.join('；'),
					'</span>',
				'</label>'
			].join('');

			// 是否比较默认值
			if(c.compareValue && selected.length){
				return selected[0] == c.value ? '' : html;
			}

			return !selected.length ? '' : html;
		},
		reset: function(){
			var self = this;
			if(self.$.drop){
				self.$.drop.reset();
				self.onDropChange({});
			}
			return self;
		}
	});
	exports.drop = SideBarDrop;

});
